#include <bits/stdc++.h>
using  namespace std;
int  n,m,a;
bool  A[1000006];
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> m;
		int ans=0;
		int maxx=0;
		for(int j=1;j<=m;j++){
			cin >> a;
			if(a>maxx){
				maxx=a;
			}
			if(A[a]==1){
				ans=ans+a;
			}else{
				A[a]=1;
			}
		}
		cout << ans << endl;
		for(int j=1;j<=maxx;j++){
			A[j]=0;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

